package com.nsoft.thickclient.trackMove.user;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;

import com.nsoft.server.serviceImpl.FacadeFactoryImpl;
import com.nsoft.thickclient.controller.ApplicationController;
import com.nsoft.thickclient.controller.ScreenView;
import com.nsoft.thickclient.trackMove.intr.user.User;
import com.nsoft.thickclient.trackMove.search.SearchAction;
import com.nsoft.thickclient.trackMove.search.SearchView;
import com.nsoft.thickclient.trackMove.search.SearchViewController;

public class SearchUserAction implements SearchAction<User> {

	public void delete(User bean) {
		// TODO Auto-generated method stub

	}

	public void edit(User bean, ApplicationController applicationController) {
		LoginViewController controller = new LoginViewController(true);
		applicationController.openScreen(controller, new Dimension(650, 300));
		controller.getUserView().setWorkingBean(bean);
	}

	public User getNewBean() {
		return new User();
	}

	public SearchView<User> getView(SearchViewController<User> controller) {
		List<User> list = new ArrayList<User>();
		for (int i = 0; i < 10; i++) {
			User user = new User();
			user.setName("name -> " + i);
			user.setLogin("login -> " + i);
			user.setRole(i % 2 == 0 ? User.USER : User.ADMIN);
			list.add(user);
		}
		/*
		 * String[] props = { "id", "name" }; NTable table = new NTable(list,
		 * props, props); JPanel panel = new JPanel(new BorderLayout());
		 * panel.add(new JScrollPane(table), BorderLayout.CENTER);
		 */

		UserView userView = new UserView(false);
		String[] properties = { "name", "login", "role" };
		String[] headers = { "Name", "Login", "Role" };
		SearchView<User> searchView = new SearchView<User>(list, properties,
				headers, userView, controller);
		return searchView;
	}

	public List<User> search(User bean) {
		return FacadeFactoryImpl.getUserService().searchUsers(bean);
	}

}
